import {
    defineStore
} from 'pinia';
import { baseAPI } from '@/api/index';

export const useTabbarStore = defineStore('tabbar', {
    state: () => {
        return {
            tabList: [
                {
                    pagePath: '/pages/index/index',
                    text: '发现'
                },
                {
                    pagePath: '/pages/discuss/index',
                    text: '话题'
                },
                {
                    pagePath: '/pages/post/publish',
                    text: '',
                    isPublish: true
                },
                {
                    pagePath: '/pages/message/index',
                    text: '消息',
                    msgCount: 0
                },
                {
                    pagePath: '/pages/my/index',
                    text: '我'
                }
            ],
            messageStats: {}
        };
    },
    actions: {
        // 设置token
        setToken(token) {
            this.token = token;
            uni.setStorageSync('token', token);
        },
        getMessageStats() {
            baseAPI.get("message/getUnreadCount").then(res => {
                if (res.code === 200) {
                    this.messageStats = res.result;
                    this.tabList[3].msgCount = res.result.total;
                }
            })
        }
    }
});